package com.erpanderp.wam.asset.view;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.erpanderp.wam.asset.model.entity.AssetDetails;
import com.erpanderp.wam.asset.model.entity.AssetMaster;
import com.erpanderp.wam.asset.model.entity.AssetRequest;
import com.erpanderp.wam.asset.model.service.AssetMasterDAO;
import com.erpanderp.wam.asset.model.service.AssetRequestDAO;

@ManagedBean
@ViewScoped
public class PrintAssetRequestBean implements Serializable{


	private static final long serialVersionUID = 1L;
	private HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
	ServletContext context = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
	HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
	private TimeZone timeZone = TimeZone.getDefault();
	
	private AssetRequest viewAssetRequest;
	private AssetDetails viewAssetMaster=new AssetDetails();
	private AssetMaster assetMaster;
	
	private List<AssetDetails> viewAssetDetailsList = new ArrayList<AssetDetails>();
	
	private AssetRequestDAO assetRequestDAO =new AssetRequestDAO();
	private AssetMasterDAO assetMasterDAO=new AssetMasterDAO();
	
	private String assetCode;

	public PrintAssetRequestBean() {
		
		  assetCode = request.getParameter("assetCode");
		  viewAssetRequest = assetRequestDAO.getAssetRequestByAssetCode(assetCode);
		  
		  if(viewAssetRequest.getRecommenderComments() == null || viewAssetRequest.getRecommenderComments().equals("")){
			  viewAssetRequest.setRecommenderComments("Pending...");
		  }if(viewAssetRequest.getApproverComments() == null || viewAssetRequest.getApproverComments().equals("")){
			  viewAssetRequest.setApproverComments("Pending...");
		  }
		  viewAssetDetailsList =assetRequestDAO.getAllAssignedAssets(viewAssetRequest.getAssetRequestId());
	}
	
	public void viewAssetDetailsListener(ActionEvent e)  {
		 
		 Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
		  
		 String assetCode = params.get("assetCode");	
		 System.out.println("assetCode=========="+assetCode);

		 assetMaster=assetMasterDAO.getAssetMasterByAssetCode(assetCode);
		  System.out.println("assetMaster============"+assetMaster);
		 
}

	
	//setters and getters
	public List<AssetDetails> getViewAssetDetailsList() {
		return viewAssetDetailsList;
	}

	public void setViewAssetDetailsList(List<AssetDetails> viewAssetDetailsList) {
		this.viewAssetDetailsList = viewAssetDetailsList;
	}


	public String getAssetCode() {
		return assetCode;
	}


	public void setAssetCode(String assetCode) {
		this.assetCode = assetCode;
	}


	public TimeZone getTimeZone() {
		return timeZone;
	}


	public void setTimeZone(TimeZone timeZone) {
		this.timeZone = timeZone;
	}


	public AssetRequest getViewAssetRequest() {
		return viewAssetRequest;
	}


	public void setViewAssetRequest(AssetRequest viewAssetRequest) {
		this.viewAssetRequest = viewAssetRequest;
	}


	public AssetRequestDAO getAssetRequestDAO() {
		return assetRequestDAO;
	}


	public void setAssetRequestDAO(AssetRequestDAO assetRequestDAO) {
		this.assetRequestDAO = assetRequestDAO;
	}


	public AssetDetails getViewAssetMaster() {
		return viewAssetMaster;
	}


	public void setViewAssetMaster(AssetDetails viewAssetMaster) {
		this.viewAssetMaster = viewAssetMaster;
	}

	public AssetMasterDAO getAssetMasterDAO() {
		return assetMasterDAO;
	}

	public void setAssetMasterDAO(AssetMasterDAO assetMasterDAO) {
		this.assetMasterDAO = assetMasterDAO;
	}

	public AssetMaster getAssetMaster() {
		return assetMaster;
	}

	public void setAssetMaster(AssetMaster assetMaster) {
		this.assetMaster = assetMaster;
	}

}
